extends ../layout
block css
  link(rel='stylesheet', href='/stylesheets/signin.css')

block content
  .container
    form#form.form-signin(method="post")
      h2.form-signin-heading Please register
      .form-group
        label.sr-only(for="inputEmail") Email address
        input#inputEmail.form-control(type="text" name="email" placeholder="Email address" value=email required autofocus)
      a#submitBtn.btn.btn-lg.btn-primary.btn-block Register

block js
  script().
    var submit = false;
    $('#submitBtn').on('click', function () {
      if (submit) {
        return ;
      }
      submit = true;
      $.ajax({
        type: 'post',
        data: $('#form').serializeArray(),
        url: "/users/registerCode",
        dataType: 'json',
        success: function (data) {
            if (data.status == "OK") {
              let email = $('#inputEmail').val();
              sessionStorage.setItem('email', email);
              location.href = '/auth/confirm?email=' + email;
              submit = false;
            } else {
              alert(data.message);
              submit = false;
            }
        }
      });
    });
